package com.aiti.lulian.controller.crad;

import com.aiti.base.core.base.controller.WebController;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.entity.LuLianEnterprise;
import com.aiti.lulian.entity.crad.CardZfSort;
import com.aiti.lulian.service.ICardZfSortService;
import com.aiti.lulian.service.ILuLianEnterpriseUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/card/zf/sort")
public class CardZfSortController extends WebController {

    private final ICardZfSortService baseService;
    private ILuLianEnterpriseUserService enterpriseUserService;
    public CardZfSortController(ICardZfSortService baseService,ILuLianEnterpriseUserService enterpriseUserService) {
        this.baseService = baseService;
        this.enterpriseUserService = enterpriseUserService;
    }


    @GetMapping("/selectWeChatList")
    public Message selectWeChatList(@RequestParam(value = "enterpriseId") String enterpriseId){
        return baseService.selectWeChatList(enterpriseId);
    }

    @GetMapping("/selectList")
    public Message selectList(){
        String userId = findUserId();
        LuLianEnterprise luLianEnterprise = enterpriseUserService.selectCurrentUserJoinEnterpriseInfo(userId);

        if(luLianEnterprise == null || StringUtils.isBlank(luLianEnterprise.getBaseId())){
            return Message.fail("没有找到绑定的企业信息");
        }
        return baseService.selectList(luLianEnterprise.getBaseId());
    }

    @PostMapping("/save")
    public Message save(@RequestBody List<CardZfSort> zfSort) {
        String userId = findUserId();
        baseService.saveData(zfSort,userId);
        return Message.success();
    }

    @PostMapping("/update")
    public Message update(@RequestBody List<CardZfSort> zfSort){
        for(CardZfSort temp : zfSort){
            if(StringUtils.isBlank(temp.getId())){
                return Message.fail("没有找到ID");
            }
        }
        baseService.updateBatchById(zfSort);
        return Message.success();
    }
}
